package domain;

public class AuthorPair {

	private Author authorA = null;
	private Author authorB = null;
	
	public AuthorPair(Author authorA, Author authorB) throws Exception {
		if (authorA == null)
			throw new Exception("AuthorA may not be null.");
		if (authorB == null)
			throw new Exception("AuthorB may not be null.");
		/*if (authorA.getAuthorID() == authorB.getAuthorID())
			throw new Exception("AuthorA may not be the same entity as AuthorB.");*/
		
		if (authorA.getFullName().compareToIgnoreCase(authorB.getAffiliation()) > 0) {
			this.authorA = authorA;
			this.authorB = authorB;
		} else {
			this.authorB = authorA;
			this.authorA = authorB;
		}
	}
	
	public Author getAuthorA() {
		return this.authorA;
	}
	
	public Author getAuthorB() {
		return this.authorB;
	}
	
	public boolean equals(Object obj) {
		if (!Author.class.isInstance(obj))
			return false;
		
		AuthorPair other = (AuthorPair)obj;
		
		return other.getAuthorA().equals(this.getAuthorA()) && other.getAuthorB().equals(this.getAuthorB());
	}
}
